﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YJKRevitKernel.FormUtility;

namespace YArchitech.HVAC
{
	public partial class FormDeleteMarks : System.Windows.Forms.Form
	{
		public FormDeleteMarks()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			List<KeyValuePair<System.Windows.Forms.Control, bool>> inputControlGroup = new List<KeyValuePair<System.Windows.Forms.Control, bool>>();
			this.m_thisManger = new ControlInfoManager(this, inputControlGroup, "{142E152E-209F-4ADC-8A46-7C4787AC1C37}", null);
			//base.Icon = Resource.YArchitechIcon;
		}

		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		private void UpdateMessageToCommand()
		{
			if (CommandDeleteMarks.hWndRevit != null)
			{
				int wMsg = 7;
				FormDeleteMarks.SendMessage(CommandDeleteMarks.hWndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
			}
		}

		private void cbPipeDiameter_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbPipeDiameter.Checked)
			{
				this.ListTypes.Add(MarkType.PipeDiameter);
			}
			else
			{
				this.ListTypes.Remove(MarkType.PipeDiameter);
			}
			this.UpdateMessageToCommand();
		}

		private void cbPipeLevel_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbPipeLevel.Checked)
			{
				this.ListTypes.Add(MarkType.PipeLevel);
			}
			else
			{
				this.ListTypes.Remove(MarkType.PipeLevel);
			}
			this.UpdateMessageToCommand();
		}

		private void cbPipeLine_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbPipeLine.Checked)
			{
				this.ListTypes.Add(MarkType.PipeLine);
			}
			else
			{
				this.ListTypes.Remove(MarkType.PipeLine);
			}
			this.UpdateMessageToCommand();
		}

		private void cbRiserPipe_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbRiserPipe.Checked)
			{
				this.ListTypes.Add(MarkType.RiserPipe);
			}
			else
			{
				this.ListTypes.Remove(MarkType.RiserPipe);
			}
			this.UpdateMessageToCommand();
		}

		private void cbSlope_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbSlope.Checked)
			{
				this.ListTypes.Add(MarkType.Slope);
			}
			else
			{
				this.ListTypes.Remove(MarkType.Slope);
			}
			this.UpdateMessageToCommand();
		}

		private void cbDuct_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbDuct.Checked)
			{
				this.ListTypes.Add(MarkType.Duct);
			}
			else
			{
				this.ListTypes.Remove(MarkType.Duct);
			}
			this.UpdateMessageToCommand();
		}

		private void cbDuctTerminal_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbDuctTerminal.Checked)
			{
				this.ListTypes.Add(MarkType.DuctTerminal);
			}
			else
			{
				this.ListTypes.Remove(MarkType.DuctTerminal);
			}
			this.UpdateMessageToCommand();
		}

		private void cbEquipment_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbEquipment.Checked)
			{
				this.ListTypes.Add(MarkType.Equipment);
			}
			else
			{
				this.ListTypes.Remove(MarkType.Equipment);
			}
			this.UpdateMessageToCommand();
		}

		private void cbRadiation_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbRadiation.Checked)
			{
				this.ListTypes.Add(MarkType.Radiation);
			}
			else
			{
				this.ListTypes.Remove(MarkType.Radiation);
			}
			this.UpdateMessageToCommand();
		}

		private void cbFloorPipe_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbFloorPipe.Checked)
			{
				this.ListTypes.Add(MarkType.FloorPipe);
			}
			else
			{
				this.ListTypes.Remove(MarkType.FloorPipe);
			}
			this.UpdateMessageToCommand();
		}

		private void FormDeleteMarks_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.SimulationPressESC();
		}

		private void SimulationPressESC()
		{
			int bVk = 27;
			int dwFlags = 0;
			int dwFlags2 = 2;
			FormDeleteMarks.keybd_event((byte)bVk, 0, dwFlags, 0);
			FormDeleteMarks.keybd_event((byte)bVk, 0, dwFlags2, 0);
		}

		private void FormDeleteMarks_Load(object sender, EventArgs e)
		{
			if (this.m_thisManger != null && !this.m_thisManger.SetControlInfoToForm())
			{
				base.Location = new System.Drawing.Point(230, 170);
			}
			base.KeyPreview = true;
		}

		private void FormDeleteMarks_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\u001b')
			{
				base.Close();
			}
		}

		private void FormDeleteMarks_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (this.m_thisManger != null)
			{
				this.m_thisManger.GetControlInfoToXml();
			}
		}

		public readonly List<MarkType> ListTypes = new List<MarkType>();

		private ControlInfoManager m_thisManger;
	}
}
